package com.xywy.fwc.adapter;

import java.util.ArrayList;
import java.util.List;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xywy.R;
import com.xywy.common.util.ImageLoaderUtil;
import com.xywy.fwc.bean.FwcHomeData;
import com.xywy.fwc.bean.ServiceData;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 服务窗口ListView适配器
 * 
 * @author yangyu
 * 
 */
public class FwcItemAdapter extends BaseAdapter {

	private Context mContext;

	private List<FwcHomeData> datas;

	public FwcItemAdapter(Context context, List<FwcHomeData> datas) {
		this.mContext = context;
		// datas = new ArrayList<ServiceData>();
		this.datas = datas;
	}

	@Override
	public int getCount() {
		if (datas == null || datas.size() < 1)
			return 0;

		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		FwcHomeData data = datas.get(position);
		if (convertView == null) {
			// arg1 =View.inflate(mContext,R.layout. , null);
			holder = new ViewHolder();
			convertView = View.inflate(mContext, R.layout.fwc_data_item, null);
			holder.icon = (ImageView) convertView
					.findViewById(R.id.me_cover_user_photo);
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.content = (TextView) convertView.findViewById(R.id.content);
			holder.from = (TextView) convertView.findViewById(R.id.from);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if(data.getFrom_id().equals(FwcHomeData.XYWY_FROMID)){
			holder.from.setText(data.getFrom());
			holder.from.setVisibility(View.VISIBLE);
		}else {
			holder.from.setVisibility(View.GONE);
		}
		holder.title.setText(data.getName());
		holder.content.setText(data.getTitle());
		ImageLoaderUtil.displayImage(data.getHeadimg(), holder.icon);
		return convertView;
	}

	class ViewHolder {
		public ImageView icon;
		public TextView title;
		public TextView content;
		public TextView from;
	}
}
